#include <iostream>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

void Div()
{
    int a=1,b=0,c=0;
    c = a / b;
}
int main()
{
    pid_t pid = fork();
    if (pid == 0)
    {
        //child
        Div();
        exit(0);
    }
    else if (pid == -1) // < 0
    {
        perror("fork fail");
    }
    //father
    int status = 0;
    pid_t n = waitpid(pid, &status, 0);
    if (n == -1)
    {
        perror("wait fail");
    }
    std::cout << "child exit code " << ((status>>8)&0xFF) << std::endl;
    std::cout << "child core dump " << ((status>>7)&0x1) << std::endl;
    std::cout << "child exit signal " << (status&0x7F) << std::endl;

    return 0;
}